package com.letian.web.controller.im;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.im.domain.ImChatMsg;
import com.letian.im.service.IImChatMsgService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 聊天信息Controller
 * 
 * @author bmz
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/info/chatMsg")
public class ImChatMsgController extends BaseController
{
    @Autowired
    private IImChatMsgService imChatMsgService;

    /**
     * 查询聊天信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:chatMsg:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImChatMsg imChatMsg)
    {
        startPage();
        List<ImChatMsg> list = imChatMsgService.selectImChatMsgList(imChatMsg);
        return getDataTable(list);
    }

    /**
     * 导出聊天信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:chatMsg:export')")
    @Log(title = "聊天信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImChatMsg imChatMsg)
    {
        List<ImChatMsg> list = imChatMsgService.selectImChatMsgList(imChatMsg);
        ExcelUtil<ImChatMsg> util = new ExcelUtil<ImChatMsg>(ImChatMsg.class);
        util.exportExcel(response, list, "聊天信息数据");
    }

    /**
     * 获取聊天信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:chatMsg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imChatMsgService.selectImChatMsgById(id));
    }

    /**
     * 新增聊天信息
     */
    @PreAuthorize("@ss.hasPermi('info:chatMsg:add')")
    @Log(title = "聊天信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImChatMsg imChatMsg)
    {
        return toAjax(imChatMsgService.insertImChatMsg(imChatMsg));
    }

    /**
     * 修改聊天信息
     */
    @PreAuthorize("@ss.hasPermi('info:chatMsg:edit')")
    @Log(title = "聊天信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImChatMsg imChatMsg)
    {
        return toAjax(imChatMsgService.updateImChatMsg(imChatMsg));
    }

    /**
     * 删除聊天信息
     */
    @PreAuthorize("@ss.hasPermi('info:chatMsg:remove')")
    @Log(title = "聊天信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imChatMsgService.deleteImChatMsgByIds(ids));
    }
}
